package com.sczmgk.hotline_pzh.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

import com.sczmgk.hotline_pzh.R;
import com.sczmgk.hotline_pzh.constants.Constants;
import com.sczmgk.hotline_pzh.sp.CacheUtils;
import com.sczmgk.hotline_pzh.utils.CommonUtils;
import com.sczmgk.hotline_pzh.utils.MyLog;
import com.sczmgk.hotline_pzh.utils.SecurityCodeUtils;

import java.util.Timer;
import java.util.TimerTask;

import cn.jpush.android.api.JPushInterface;


/**
 * Created by Administrator on 2016/12/20 0020.
 */

public class SplashActivity extends Activity {

    private final String TAG = SplashActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE) ;
        setContentView(R.layout.activity_splash);
        SecurityCodeUtils.getIndicatorData(this,null);
        delay() ;

        initData() ;

        setListener() ;
    }

    /**
     * 延迟5秒进入界面(如果是第一次进入,则进入引导页,否则进入主界面)
     */
    private void delay() {

        final boolean isOpenMainPage = CacheUtils.getBooleanData(this, Constants.IS_OPEN_MAIN_PAGE_KEY, false);
        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                if (isOpenMainPage) {

                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                } else {
                    startActivity(new Intent(SplashActivity.this, GuideActivity.class));
                }
//                MyApp.hxImUtils.initIm();
                finish();
            }
        }, 3000);
    }

    private void initData() {

        if(CacheUtils.getBooleanData(getApplicationContext(), Constants.IS_LOGIN_KEY, false)){

            MyLog.e(TAG,"不需要登录，调用单点方法----------");
            CommonUtils.reportImei(getApplicationContext());
        }else{
            MyLog.d(TAG,"未登录 ------");
        }
    }

    private void setListener() {

    }
    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.init(this);            // 初始化 JPush
        JPushInterface.setDebugMode(true);    // 设置开启日志,发布时请关闭日志
        JPushInterface.onResume(getApplicationContext());
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(getApplicationContext());

    }
}
